package com.pointcircle.core;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class JpaBaseEntity<ID extends Serializable> {

	@Column(name = "create_time")
	protected Date createTime;
	
	@Column(name = "create_user")
	protected String createUser;
	
	@Column(name = "update_time")
	protected Date updateTime;
	
	@Column(name = "update_user")
	protected String updateUser;

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public boolean isNew() {
		return this.getId() == null;
	}
	public abstract ID getId();
	public abstract void setId(ID id);
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object entity) {
		if(entity != null) {
			if(entity.getClass().equals(this.getClass())) {
				return this.getId().equals(((JpaBaseEntity<ID>) entity).getId());
			}
		}
		return false;
	}
}
